home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12560 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: HELP ! Need a DELAY routine
  5. Date: Wed, 20 Mar 1996 11:18:06 -0500
  6. Organization: Datalytics, Inc
  7. Message-ID: <31502FBE.165F@datalytics.com>
  8. References: <4ihh45$css@aldebaran.sct.fr> <4ik551$14k@reader2.ix.netcom.com>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. John Lilley wrote:
  16. > In article <4ihh45$css@aldebaran.sct.fr>, winter@worldnet.net says...
  17. > >
  18. > >I'm programming an emulator for an old computer. To make it run
  19. > >properly, I need a special routine in C to make a delay in ms.
  20. > >For example, I would like to make a 60ms delay, or a 20ms delay.
  21. > >How can I do this ? The delay() function is 1000% bugged.
  22. > Be more specific.  Which computer/compiler?
  23. > john lilley
  24.  
  25. In general, if you have a library routine or OS call you can 
  26. make that returns time in seconds or some other resolution, you 
  27. can call a designated loop repeatedly until ten times the timer 
  28. routine's resolution has elapsed.  You now have a basis for the 
  29. number of times to call your delay loop for a given time delay.  
  30. Using that basis, you can now calculate the number of times to 
  31. call your delay routine to effect a specific delay.
  32.  
  33. The idea is to ensure that the delay loop, which just loops a 
  34. predetermined number of times, is called enough times that the 
  35. aggregate calls consume the desired time.  By calibrating the 
  36. duration of the inner delay loop, you can make your outer delay 
  37. routine accurate among various speed processors.
  38.  
  39. The alternative, just looping 1000 times, for example, was a 
  40. classic mistake of years ago.  Programs that worked fine on a 
  41. slow machine would run ridiculously fast on newer, faster 
  42. computers.
  43.  
  44. -- 
  45. Robert Stewart        | My opinions are usually my own.
  46. Datalytics, Inc.    | stew@datalytics.com
  47.